<!-- 搜索表单 -->
<template>
  <ele-card :body-style="{ paddingBottom: '2px' }">
    <el-form label-width="72px" @keyup.enter="search" inline>
      <el-form-item label="所属站点">
        <el-radio-group v-model="form.site_id" @change="search">
          <el-radio-button :value="0" :label="0">全部</el-radio-button>
          <el-radio-button
            v-for="item in cityList"
            :key="item.site_id"
            :label="item.site_id"
            :value="item.site_id"
          >
            {{ item.region_name }}
          </el-radio-button>
        </el-radio-group>
      </el-form-item>
      <br />
      <el-form-item label="类型">
        <el-radio-group v-model="form.type" @change="search">
          <el-radio-button label="全部">全部</el-radio-button>
          <el-radio-button label="线上">钱包</el-radio-button>
          <el-radio-button label="第三方">灵活用工</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <br />
      <el-form-item label="所属公司">
        <el-radio-group v-model="form.tenant_id" @change="search">
          <el-radio-button :label="0" :value="0"> 全部 </el-radio-button>
          <el-radio-button
            v-for="item in tenantList"
            :key="item.id"
            :label="item.id"
            :value="item.id"
          >
            {{ item.title }}
          </el-radio-button>
        </el-radio-group>
      </el-form-item>
      <br />
      <el-form-item label="状态">
        <el-radio-group v-model="form.status" @change="search">
          <el-radio-button :label="0">待审核</el-radio-button>
          <el-radio-button :label="2">已审核</el-radio-button>
          <el-radio-button :label="-1">已拒绝</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <br />
      <el-form-item label="记录范围">
        <el-radio-group v-model="form.all" @change="search">
          <el-radio-button :label="0">最近</el-radio-button>
          <el-radio-button :label="1">所有记录</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <br />
      <el-form-item label="工作编号">
        <el-input clearable v-model.trim="form.code" />
      </el-form-item>

      <el-form-item label="姓名">
        <el-input v-model="form.realname" clearable />
      </el-form-item>
      <el-form-item label="电话">
        <el-input v-model="form.tel" clearable />
      </el-form-item>
      <el-form-item label="企业名称">
        <el-input v-model="form.company_name" clearable />
      </el-form-item>
      <br />
      <el-form-item label="开始时间">
        <el-date-picker
          v-model="form.startDate"
          type="date"
          value-format="YYYY-MM-DD"
        />
      </el-form-item>
      <el-form-item label="结束时间">
        <el-date-picker
          v-model="form.endDate"
          type="date"
          value-format="YYYY-MM-DD"
        />
      </el-form-item>
      <el-form-item label="归属月份">
        <el-date-picker
          v-model="form.belongs_date"
          class="filter-item"
          type="month"
          value-format="YYYY-MM"
        />
      </el-form-item>

      <br />
      <el-form-item label="提交日期">
        <el-date-picker
          v-model="form.createTime"
          type="date"
          value-format="YYYY-MM-DD"
        />
      </el-form-item>
      <el-form-item label="审核日期">
        <el-date-picker
          v-model="form.judgeTime"
          type="date"
          value-format="YYYY-MM-DD"
        />
      </el-form-item>
      <br />
      <el-form-item label="提交人">
        <el-select
          v-model="form.create_user_id"
          class="filter-item"
          placeholder="提交人"
          style="width: 150px"
          filterable
          clearable
        >
          <el-option label="全部" :value="0" />
          <el-option
            v-for="item in adminList"
            :key="item.id"
            :label="item.realname"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="审核人">
        <el-select
          style="width: 150px"
          v-model="form.judge_user_id"
          placeholder="审核人"
          filterable
          clearable
        >
          <el-option label="全部" :value="0" />
          <el-option
            v-for="item in adminList"
            :key="item.id"
            :label="item.realname"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <br />

      <el-form-item label-width="16px">
        <el-button type="primary" @click="search">查询</el-button>
      </el-form-item>
    </el-form>
  </ele-card>
</template>

<script setup>
  import { ref } from 'vue';
  import { EleMessage } from 'ele-admin-plus/es';
  import { useFormData } from '@/utils/use-form-data';
  import { getCityList } from '@/api/system/region';
  import { getTenantList } from '@/api/tenant';
  const emit = defineEmits(['search']);

  const props = defineProps({
    where: Object
  });
  /** 站点数据 */
  const cityList = ref([]);
  /** 表单数据 */
  const [form] = useFormData({
    code: '',
    all: 0,
    tenant_id: 0,
    company_name: '',
    site_id: 0,
    status: 2,
    cate: '正常',
    type: '线上',
    tel: '',
    realname: '',
    endDate: '',
    startDate: '',
    job_id: 0,
    student_id: 0,
    create_user_id: 0,
    judge_user_id: 0,
    company_id: 0,
    belongs_date: '',
    createTime: '',
    judgeTime: '',
    judge_time: '',
    myCreate: 0
  });
  /** 默认搜索 */
  if (props.where) {
    form.judgeTime = props.where.judgeTime ?? '';
  }
  /** 获取站点数据 */
  getCityList({})
    .then((res) => {
      cityList.value = res.list;
    })
    .catch((e) => {
      EleMessage.error(e.message);
    });

  /** 租户数据 */
  const tenantList = ref([]);

  /** 获取租户数据 */
  getTenantList({})
    .then((res) => {
      tenantList.value = res.list;
    })
    .catch((e) => {
      EleMessage.error(e.message);
    });

  /** 搜索 */
  const search = () => {
    console.log(form);
    emit('search', { ...form });
  };
</script>
